import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

def load_trace_pps_file(filename):
    df_data = pd.read_csv(filename, header = None)
    pre_time = 0
    gap_list = []
    time_list = []
    for index, row in df_data.iterrows():
        if row[0] < 0:
            row[0] = - row[0]
        gap = row[0] - pre_time
        gap_list.append(gap)
        pre_time = row[0]

        time_list.append(row[0])

    # print(gap_list)
    # print(max(gap_list))
    # print(min(gap_list))
    # print(np.mean(gap_list))
    return time_list, gap_list

if __name__ == '__main__':
    time_list, gap_list = load_trace_pps_file('downlink-1686214831.pps')

    plt.figure(figsize=(6, 3))
    plt.plot(time_list, gap_list)
    
    plt.xlabel('Time (ms)')
    plt.ylabel('Gap (ms)')
    plt.grid()
    plt.tight_layout()
    file_name = __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.png", bbox_inches='tight')